5 Replies Latest reply on Mar 11, 2012 1:17 PM by Rainman

    relationship problem

    Rainman

      Title

      relationship problem

      Post

      Could You please help me with this one. I'am making a db to store observations of my patients.

       

      I have a main table - "Patients" with all pts  details related via __kp_PatientID field

      and I have a second Table with "Observations" related via __kf_PaitentID to the Patients Table

      On the observations layout I have two fields

      "Date of observations" and "Observation text"

      How can I relate multiple records of observations with date field..... to exact patient  - becouse  in dynamic table it shows only first observations

      and which script should I use to have a button with "add new observations" so it activats new field to fill in

      I hope you understand me :D

      Thank You!

        • 1. Re: relationship problem
          bumper

          I'm not sure of your schema or your UI, (what's a dynamic table?) but it sounds to me like you have a simple one to many relationship. One patient to many observations, so what you are describing as your relationship should be working. The patientID is the primary key and that number will be used as a foreign key to relate the many records there back to the patient, ie, every observation record for the same patient will have that patient's _kp_PatientID in the _kf_PatientID field in the Observation record.

          How you are looking at them is possibly the problem, you can either use a portal on the patient record, sort by date and have a scroll bar to move through the records or use a go to related record to move to an observation table. Or you can do both, but I'm getting ahead of your problem.

          And to answer the script question as well, open up a copy of the Contact Management template and look at how that file handles Notes, both through a portal and the script to create a new Note record. This was included to serve as an example of how to script a new related record, but it bears mentioning that by turning on the Allow creation of new records via this relationship check box you could create a new record just by entering data in your observations field.

          You might get additional info from my early morning mini treatise on this subject in my response to "Relationships For crying out loud" which was culmination of four hours of hand to hand combat with FM in setting up a UI for med tech's to quickly (and accurately) enter data for saliva drug screens. 

          • 2. Re: relationship problem
            Rainman

            Thank You for your answer. 

             

            Everything works great...

            In my previous method ->

            I have created a osbservation chart layout for print - with patient name  id number and each observation was stored to separate field ob1 ob2 ob3. And ob fields where grouped on my print layout.

             

            But now with your method there one field (Notes:: text) and different records for this field. So How can I group all records for one field on one layout with additionaly patient name and id number?

             

            thanx a lot

            • 3. Re: relationship problem
              bumper

              As I read your last comment you have two tables, Patients and Observations. They are related by the Patient ID fields. Now you have added a third, Notes, also related by Patient ID. You can continue to use the Observation Table and just break the fields into separate records or move the data from the Observations table into new records in the Notes table. Regardless of which one you use they have to be related to the Patient table by the ID fields.

              Once they are related then there are several methods of having the Notes data displayed with the patient information. The first method is to put a portal on the patient layout as is done in the Contacts Management template. This allows you to scroll through all the Notes records for just that patient and if you sort the relationship by date, descending order, then they will be shown last to first. You can put multiple fields in the portal, date, time and record creator, plus your data fields. You can even put a scroll bar in the Notes text field allow you to add and review more data that initially seen. Or you could put your multiple Observation fields in the portal row, but I would only do this if the individual fields are for different bits of data, B/P, weight, Chief Complaint, etc.

              If you just wanted to look at all the Notes records for that patient, you could use Go to related records and move to a layout based on Notes. Since relationships are bidirectional you could put the patient's name and id in the header and all the notes in a list in the body.

              • 4. Re: relationship problem
                Rainman

                Ok Thanks a lot, I'm copmletely new to FM but I'm starting to embrace all of it

                 

                Could You please explain me this one how to do it? Sorry for such questions :/

                Thnx

                If you just wanted to look at all the Notes records for that patient, you could use Go to related records and move to a layout based on Notes. Since relationships are bidirectional you could put the patient's name and id in the header and all the notes in a list in the body.

                • 5. Re: relationship problem
                  Rainman

                  Ok thanks I did it ;)