Represent nested resources with two different type owners (Entites) in REST APIs?

Suppose I have an entity named Appointment, This entity represents a medical appointment between you Doctor and a Patient,

How to create a new one AppointmentI send something like:

POST /appointments

  "doctorId": 98173821,
  "patientId": 2138212,
  ... omitted for brevity

Works well.

As you can see, this object is nested with two other resources (Patient and Doctor)

Imagine being logged Patient (with his JWT token) wants to see his story from Appointments,

Today I send a request to:

GET /patients/2138212/appointments?page=1&size=2&startDate=2019-01-01&endDate=2019-08-01

(please do not hesitate to criticize)

since this is a story, it is not necessary to retrieve the whole thing Appointment Objects. The answer only retrieves basic information about that Appointments, The answer looks like this:

  "timestamp": 1566216359,
  "transactionId": "6eed92831cad128",
  "data": {
    "appointments": (
        "id": 6372,
        "doctorId": 98173821,
        "date": "2019-01-01"
        "id": 6985,
        "doctorId": 98173821,
        "date": "2019-02-01"

What if that Patient Choose a specific one Appointment in the frontend and the detailed information on this specific Appointment must be shown? What is the best way to model such a REST endpoint?

My options:

  • GET /patients/2138212/appointments/6372
  • GET /appointments/6372

The first one looks good and follows REST patterns on nested resources, as it can do that Appointment 6372 belongs to the Patient 2,138,212th

The second does not provide readability. I mean, when I look at the resource, I do not know who it belongs to Appointment, That's why I prefer the first approach.

Now it goes down the street Doctor must see the story of his appointments.

Today I send a request to:

GET /doctors/98173821/appointments?page=1&size=2&startDate=2019-01-01&endDate=2019-08-01

(please do not hesitate to criticize)

The answer looks like this:

  "timestamp": 1566216359,
  "transactionId": "6eed92831cad321",
  "data": {
    "appointments": (
        "id": 6372,
        "patientId": 2138212,
        "date": "2019-01-01"
        "id": 6985,
        "patientId": 2138212,
        "date": "2019-02-01"

What if that Doctor Choose a specific one Appointment in the frontend and the detailed information on this specific Appointment must be shown? What is the best way to model such a REST endpoint?

My options:

  • GET /doctors/98173821/appointments/6372
  • GET /appointments/6372

The questions I have:

  1. How can you represent a nested resource with "two owners"? Is there a better approach than this to which I refer in this question?
  2. To the history of AppointmentsI was suggested to do that /appointments/doctors/{doctorId} and /appointments/patients/{patientId}I do not agree at all since Doctor and the Patient has the Appointment. not the opposite, What do you suggest?

Arrays – Nested logical function in array formulas in Google Sheets

ArrayFormula (if (len (A2: A), IF (ARRAYFORMULA ((Z2: Z> (TAX! A3 / 24)) * (Z2: Z <= (TAX! B3 / 24))), (TAX! C3 / 24) + ((Z2: Z- (TAX! A3 / 24))TAX! D3), ​​IF (ARRAYFORMULA ((Z2: Z> (TAX! A4 / 24))(Z2: Z <= (CONTROL! B4 / 24)), (CONTROL! C4 / 24) + ((Z2: Z- (CONTROL! A4 / 24))TAX! D4), IF (ARRAYFORMULA ((Z2: Z> (TAX! A5 / 24))(Z2: Z <= (CONTROL! B5 / 24)), (CONTROL! C5 / 24) + ((Z2: Z- (CONTROL! A5 / 24))TAX! D5), IF (ARRAYFORMULA ((Z2: Z> (TAX! A6 / 24))(Z2: Z <= (CONTROL! B6 / 24)), (CONTROL! C6 / 24) + ((Z2: Z- (CONTROL! A6 / 24))TAX! D6), IF (ARRAYFORMULA ((Z2: Z> (TAX! A6 / 24))(Z2: Z <= (CONTROL! B6 / 24)), (CONTROL! C6 / 24) + ((Z2: Z- (CONTROL! A6 / 24))TAX! D6), IF (ARRAYFORMULA ((Z2: Z> (TAX! A7 / 24))(Z2: Z<=(TAX!B7/24))),(TAX!C7/24)+((Z2:Z-(TAX!A7/24))*TAX!D7),IF((Z2:Z>(TAX! A8 / 24)), ARRAYFORMULA ((Z2: Z- (CONTROL! C8 / 24)) + ((TAX! A8 / 24) * TAX! D8))))))) ""))

1st question: Do not fill in the rest of the lines with the above information
2. Question: Is there a way to simplify the above formula?

Edit value in nested assignment

Here is a simplified version of my problem.

I have a nested association.

worksheet = <|"startDate" -> 
   DateObject({2017, 8, 10}, "Day", "Gregorian", -5.`), 
  "eventList" -> {
    <|"eventName" -> "Thursday Stratified 49r Pairs", 
     "eventTotal" -> 336.`|>,
    <|"eventName" -> "Thursday Aftt Side Pairs",
      "eventTotal" -> 240.`|>}|>

Below are the keys

(* {"startDate", "eventList"} *)

I have a feature to fix the names in the eventList if they are bad. Simplified function is:

fixName(name_) := Module(
   newName = name
  newName = StringReplace(newName, "Aftt" -> "Aft")

Below is the input name and the corrected name for the second entry in eventList

(* "Thursday Aftt Side Pairs" *)

(* "Thursday Aft Side Pairs" *)

I would like Scan the names in eventList and replace the corrected name with the name entered.

I have tried the following:

    len = Length(wsIn("eventList")),
    wsOut = wsIn
    (wsOut("eventList")((#))("eventName") = 
       fixName(wsOut("eventList")((#))("eventName"))) &,

However, this leads to an error

Association::setps: <|eventName->Thursday Stratified 49r Pairs,
                     eventTotal->336.|> in the part assignment
is not a symbol.

Need help with this code.

woocommerce – The return function for nested control query arguments returns incorrect arguments

I spend the price of products that satisfy my control query condition where multiple control queries are nested by "AND". Here is my code

$args = my_brands_loop(('brand_name'=>'mytag','shapes'=>'circle'));
    $loop = new WP_Query( $args );
    if ( $loop->have_posts() ) {
       while ( $loop->have_posts() ) : $loop->the_post();
           //wc_get_template_part( 'content', 'product' );
           $product = wc_get_product(get_the_ID());
           echo "
" . $product->sku ."
"; endwhile; } else { echo __( 'No products found' ); } wp_reset_postdata(); function my_brands_loop($term_taxonomies){ $term_array = array(); foreach($term_taxonomies as $k=>$v){ array_push($term_array, array( 'taxonomy' => $k, 'field' =>'slug', 'terms' => $v ) ); } $x = implode(",",$term_array); $args = array( 'post_type' => 'product', 'tax_query' => array( 'relation' => 'AND', $x ), ); return $args; }

This will return the wrong SKU values. I get correct SKU values ​​when I put the args in the loop as follows

    $args = array(
       'post_type' => 'product',
       'tax_query' => array(
          'relation' => 'AND',
             'taxonomy' => 'brand_name',
             'field'    => 'slug',
             'terms'    => 'mytag',
              'taxonomy' => 'shapes',
               'field'   =>'slug',
               'terms'  =>'circle',


But how do you get the arguments about the function and get the right SKU values?

Features – Force correct variable bindings and avoid renaming contradictory variables in nested scope constructs

Scoping constructs, lexical scoping and variable renaming

It pays to understand a little bit more about how the scoping constructs work and what happens behind the scenes when you run one. In addition to the documentation, this has been partially discussed here, but let's present a summary.

When lexical scoping construct Sc(vars, body) executes (where Sc can be for constructs like With.Module. Function), the evaluation will be carried out in approximately the following steps (or at least in our current understanding):

  • First, the list of local variables vars is analyzed.
  • The body is analyzed and the presence of inner-region constructs is tested. This test is performed literally so that, to be recognized, an inner scoping construct is created ScInner must be present in body in the shape ScInner(innerVars, innerBody), If the Inner Scope construct is dynamically generated at runtime (via ScInner @@ ... or otherwise) is not recognized by Sc during this phase.
  • When finding inner-scope constructs that conflict with some variables vars, then Sc rename them. It is important to emphasize that it is Sc that's what makes these renames in the inner scoping constructs. In fact, they are inert during this phase (since Sc Has HoldAll Attribute and such body is not rated), so Sc is the only function that is able to make these renames.
  • The actual variable binding takes place. The body is searched for instances of varsand these instances are lexically bound to the variables.
  • Depending on the nature of the scoping construct, further actions may be taken. Function does nothing, With performs the replacement of symbols (variables) with their values ​​in body (after bindings) while Module creates var$xxx Variables (corresponding to the bindings, both in the initialization and in the body) and then performs variable initializations.
  • The code in body may actually evaluate.

How to Deceive Scoping Constructs

From the above description, it is clear that if one wishes to avoid renaming an inner lexical scope construct ScInner(innerVars, innerBody) For some reason, you have to generate this code dynamically so that it does not exist inside Sc literally. Again, it may be depending on the situation that you want to evaluate or not innerVars and innerBody,

Often you want to prevent such an evaluation, so it is typical to use something like this

With({y = boundToZ}, With @@ Hold({y = z}, boundToZ)) 


With({y = boundToZ}, Hold({y = z}, boundToZ) /. Hold -> With)

or anything else that would prevent that innerVars or innerBody from unwanted early evaluation.

Here is a more meaningful example. The following is a new scope construct that executes code code with a variable var Binding to a current value extracted from a Java Iterator object:

SetAttributes(javaIterate, HoldAll);
javaIterate(var_Symbol, code_)(iteratorInstance_?JavaObjectQ) :=
        With @@ Hold({var = iteratorInstance@next()}, code)

The iteratorInstance This is expected to be a Mathematica reference for implementing Java objects Iterator Interface. The variable var is bound to the current value of the iterator (extracted via iteratorInstance@next()) With With, This is not trivial as we construct this With from pieces and thus create a lexical bond of it var to the occurrences of var in the codeat every iteration of the While Loop. In this case, it is actually the outer protection zone construct SetDelayed, And we need the construct With @@ Hold(...) To prevent variables var Rename, that's exactly what we do not want here.

However, there are cases where we want some or all innerVars or innerBody prior to the binding stage for the inner scoping constructs. The present case falls into this category. In such a case, it may be easiest to use Sc @@ {innerVars, innerBody}which is what acl did in his answer.

The case at hand

It is now clear why this solution works:

Module({x, expr},
 expr = 2 x;
 Function @@ {x, expr}
Function(x$5494, 2 x$5494)

There was no line Function(x,...) present them literally, Module did not recognize it. And since we want the variable and the body to be evaluated before Function performs the variable bindings, the second version (Function @@ {...}) was used.

You will notice that Evaluate is not needed there List That does not exist HoldAll Attribute. This particular syntax is not the only approach. For example h(x, expr) /. h -> Function or ReplacePart({x, expr}, 0 -> Function) would also work because there is no explicit Function(x, . . .) in the code.

It is instructive to note that this version also works:

Module({x, expr}, 
   expr = 2 x;
   Function(Evaluate(x), Evaluate(expr))

while Function(...) Here is the presence of extra present Evaluate around x in the Function made it impossible for Module recognize the conflict. Of course, there are many other ways to achieve the same effect.

It is now clear why the following will happen Not Job:

Module({x, expr},
 expr = 2 x;
 Function(x, z) /. z -> expr
Function(x, 2 x$151)

The point is, the substitution z -> expr happens only on stage when the body of the Module is evaluated while the binding stage takes place earlier (as described above). During the binding phase Module recognizes the name conflict in order and renames it of course. Just then is x converted into a newly created x$151and only then the code inside Module is executed – until this time it is too late because the symbols are inside Function and expr are different.

The case of Block

Block is a natural approach to protecting against global values, but as Szabolcs Comments It must be used with care. Block there is no scoping construct for the automatic rename described in the tutorial. You can also see an additional relevant discussion here. This will not give you the "protection" you are used to. Using the example of Szabolcs:

f(z_) := Block({x, expr}, expr = 2 x + z; Function(x, Evaluate(expr)))

Function(x, 3 x)

Note that this function triples its argument instead of doubling and adding it Global`x That may or may not be what you expected. Such an injection is often very useful, but at the same time, if you are used to the automatic renaming behavior (even if you do not know the mechanism), this can be a surprise.

Taxonomy Terms – Implementing a Context Filter in a Nested Taxonomy View?

We have a menu with submenus, for example:












When you click MenuItem1, the view will display the linked titles for all content that has been tagged for MenuItem1 (using taxonomy, for example, Main Taxonomy).

If we then click on Sub1A, we want to see the linked titles that we have marked in a second taxonomy (for example, sub-taxonomy), but we do not want the titles to be displayed only by clicking MenuItem1 but only these submenu items.

If you then click on the Sub1A menu, linked titles will be displayed that are tagged and only displayed if the taxonomy applied to Sub1A.

Sub1A Content1

Sub1A Content2

Sub1A Content3

Then we would like to click on Sub1A Content1 and finally get to this content, without anything else being displayed on this page. None of these other linked titles the view gave us.

We try to use nested taxonomy but can not ensure that the content appears consistent as desired. I think it's a combination of nested taxonomy and a context filter, but it can not sum up everything.

Any ideas on how to consistently display when you click through the menu? Thank you very much.

javascript – access to parent in a nested object

I'm looking for a way to access the parent object when I use nested objects. I have a complex situation, so I can not offer a real example here.

I wrote a very simple example instead.

  1. I'm getting a javascript object from queryselector ().
  2. Then I add my own property with the name receive about what an object itself is.
  3. I want to get access to the parent JavaScript object when the nested object is called elem in the elem.get.text () the time execution reaches inwards Text() Function:
// ***** initialization:
var get = {
text: function () {
// Here I would like to know what the item was
return elem.textContent;
foo: function () {},
bar: function () {}

var elem = document.querySelector ("# elem");
elem.get = Object.create (get);
// *****

Function getText (e) {
var elem =;
alert (elem.get.text ());

Again, I emphasize that it is just a simple example, so do not criticize that I could get the text of the input in a much simpler way.

In fact, I want to know how to get access on when the time comes b in the a.b () without using a global variable.

Nested Python dictionary with arrays of lists in Panda's data frame

I have a Python dictionary in the following format:

{& # 39; data & # 39 ;: {& # 39; Future_Col_Name_1 & # 39 ;: [['time_stamp_1', val_11].  ['time_stamp_2', val_12], ...].
& # 39; # 39 & Future_Col_Name_2 ;: [['time_stamp_1', val_21].  ['time_stamp_2', val_22], ...]]}}

And I have to convert this into a data frame in the following format:

                Future_Col_Name_1 Future_Col_Name_2 TimeStamp
0 val_11 val_12 time_stamp_1
1 val_21 val_22 time_stamp_2  

Any help or nudge in the right direction would be great, this is my only 2nd python script. The dictionary was created using a REST API call to retrieve data from the API of a client database. The data frame is needed to read the data into my SQL. The values ​​& # 39; time_stamp_1 & # 39; and & # 39; time_stamp_2 & # 39; are repeated in the dictation, but appear only once in the data frame.